import { LVector3 } from "../../Moduls/Tools/LMath";
import StepManager from "../StepManager";
import PlayerControler from "./PlayerControler";
import GameHandler, { BufType } from "../GameHandler";


export default class DiamondAction extends Laya.Script {
    public DetecTarget: Laya.Sprite3D;
    private self:Laya.Sprite3D;

    private playerControler: PlayerControler;

    constructor() {
        super();
    }

    onAwake() {
        this.self = this.owner as Laya.Sprite3D;
    }

    onStart() {
    }

    public SetDetecTarget(target: Laya.Sprite3D) {
        this.DetecTarget = target;
    }

    onUpdate() {
        let distance = 0;
        if(GameHandler.PalyerBuf[BufType.Magnet] == true)
        {
            distance = GameHandler.MagnetCollectDistance;
        }
        else
        {
            distance = GameHandler.CollectDiamondDistance;
        }
        if( Math.abs(this.self.transform.position.x-this.DetecTarget.transform.position.x) > distance ||
        Math.abs(this.self.transform.position.x-this.DetecTarget.transform.position.x) > distance)
        {
            return;
        }
        if(Laya.Vector3.distance(this.self.transform.position,this.DetecTarget.transform.position) < distance){
            this.self.active = false;
            Laya.stage.event("DiamondCollect", this.self.transform.position);
        }
    }
}